import from_xlsx
Turn a xlsx file to i18n file(s)
Command
# Display help for import from_xlsx
npx @jy95/i18n-tools import from_xlsx --help
Purpose
Suppose you have a xlsx file structured as :
This command helps you to turn this into several i18n json files :
- fr.json
- nl.json
- de.json
fr.json
{
"commons":{
"myNestedKey":"Hello world FR",
"myNestedArray":[
"1 FR",
"2 FR",
"3 FR"
]
},
"array":[
"1 FR",
"2 FR",
"3 FR"
],
"simpleKey":"[FR] not setted key",
"Key with spaces":[
{
"test":"42 is the answer"
}
],
"Missing key in DE":"present"
}
nl.json
{
"commons":{
"myNestedKey":"Hello world NL",
"myNestedArray":[
"1 NL",
"2 NL",
"3 NL"
]
},
"array":[
"1 NL",
"2 NL",
"3 NL"
],
"simpleKey":"[NL] not setted key",
"Key with spaces":[
{
"test":"42 is the answer"
}
],
"Missing key in DE":"present"
}
de.json
{
"commons":{
"myNestedKey":"Hello world DE",
"myNestedArray":[
"1 DE",
"2 DE",
"3 DE"
]
},
"array":[
"1 DE",
"2 DE",
"3 DE"
],
"simpleKey":"[DE] not setted key",
"Key with spaces":[
{
"test":"42 is the answer"
}
]
}
Examples of settings
- Paths
- Objects/Arrays
- Settings.js
npx @jy95/i18n-tools import from_xlsx --settings "/absolutePath/to/settings1.json"
settings1.json
{
"input":"D:\\workspace\\i18n-tools\\test\\fixtures\\import-xlsx\\export-xlsx.xlsx",
"columns":"D:\\TEMP\\TEMP\\tests-for-import\\correct\\columns.json",
"locales":[
"FR",
"NL",
"DE"
],
"outputDir":"D:\\TEMP\\TEMP\\tests-for-import",
"suffix":"_settings1"
}
columns.json
{
"technical_key":"Technical Key",
"locales":{
"FR":"French translation",
"NL":"Dutch translation",
"DE":"German translation"
}
}
npx @jy95/i18n-tools import from_xlsx --settings "/absolutePath/to/settings2.json"
settings2.json
{
"input":"D:\\workspace\\i18n-tools\\test\\fixtures\\import-xlsx\\export-xlsx.xlsx",
"columns":{
"technical_key":"Technical Key",
"locales":{
"FR":"French translation",
"NL":"Dutch translation",
"DE":"German translation"
}
},
"locales":[
"FR",
"NL",
"DE"
],
"outputDir":"D:\\TEMP\\TEMP\\tests-for-import",
"suffix":"_settings2"
}
npx @jy95/i18n-tools import from_xlsx --settings "/absolutePath/to/settings3.js"
settings3.js
module.exports = {
input: "D:\\workspace\\i18n-tools\\test\\fixtures\\import-xlsx\\export-xlsx.xlsx",
columns: {
technical_key: "Technical Key",
locales: [
["FR", "French translation"],
["NL", "Dutch translation"],
["DE", "German translation"],
].reduce(
(prev, [locale, label]) =>
Object.assign(prev, {
[locale]: label,
}),
{}
),
},
locales: ["FR", "NL", "DE"],
outputDir: "D:\\TEMP\\TEMP\\tests-for-import",
suffix: "_settings3",
};
FAQ
I want as result flat JSON file(s). How can I achieve that ?
Simply set option keySeparator
to false
in your settings.json
or settings.js
, such as :
settings.json
{
"keySeparator": false
}